package com.wdy.service.impl;

import java.util.List;

import com.wdy.dao.ComplaintDao;
import com.wdy.po.Complaint;
import com.wdy.po.Page;
import com.wdy.po.Result;
import com.wdy.po.Tenement;
import com.wdy.service.ComplaintManager;
import com.wdy.util.PageUtil;

public class ComplaintManagerImpl implements ComplaintManager {

	private ComplaintDao complaintDao;
	
	public void setComplaintDao(ComplaintDao complaintDao) {
		this.complaintDao = complaintDao;
	}

	
	public void saveComplaint(Complaint complaint) {
		complaintDao.save(complaint);
	}

	
	public void removeComplaint(Complaint complaint) {
		complaintDao.delete(complaint);
	}

	
	public void updateComplaint(Complaint complaint) {
		complaintDao.attachDirty(complaint);
	}

	
	public Complaint getComplaint(Integer id) {
		return complaintDao.findById(id);
	}


	public List<Complaint> listAll() {
		return complaintDao.findAll();
	}

	
	public List<Complaint> findByExample(Complaint complaint) {
		return complaintDao.findByExample(complaint);
	}


	public List<Complaint> findByDate(String value) {
		return complaintDao.findByDate(value);
	}


	public List<Tenement> findTenement(Object value) {
		return complaintDao.findTenement(value);
	}

	
	public Result listComplaint(Page page) {
		int totalRecords = this.complaintDao.getComplaintCount();
		page = PageUtil.createPage(page, totalRecords);
		List<Complaint> complaints = (List<Complaint>)this.complaintDao.getComplaintByPage(page);     
		return new Result(page, complaints);
	}

}
